package com.meetingshow.meeting.service;

import java.util.ArrayList;
import java.util.List;

import com.meetingshow.common.base.dao.model.QueryStruct;
import com.meetingshow.common.base.service.BaseServiceImp;
import com.meetingshow.common.base.service.model.QueryResults;
import com.meetingshow.meeting.dao.MeetingDAO;
import com.meetingshow.meeting.dao.UserFollowDAO;
import com.meetingshow.meeting.dao.model.UserFollowPO;
import com.meetingshow.meeting.service.model.UserFollowQueryParas;
import com.meetingshow.meeting.service.util.UserFollowQueryParasBuilder;
import com.meetingshow.meeting.service.util.UserFollowServiceParas;

public class UserFollowServiceImp extends BaseServiceImp implements
        IUserFollowService {

    private UserFollowDAO userFollowDAO;
    private MeetingDAO meetingDAO;
    
    /**
     * @return the userFollowDAO
     */
    public UserFollowDAO getUserFollowDAO() {
        return userFollowDAO;
    }

    /**
     * @param userFollowDAO the userFollowDAO to set
     */
    public void setUserFollowDAO(UserFollowDAO userFollowDAO) {
        this.userFollowDAO = userFollowDAO;
    }
    
    /**
     * @return the meetingDAO
     */
    public MeetingDAO getMeetingDAO() {
        return meetingDAO;
    }

    /**
     * @param meetingDAO the meetingDAO to set
     */
    public void setMeetingDAO(MeetingDAO meetingDAO) {
        this.meetingDAO = meetingDAO;
    }

    @Override
    public Integer saveUserFollow(UserFollowPO userFollowPO) throws Exception {
        Integer id = getUserFollowDAO().saveUserFollow(userFollowPO);
        getMeetingDAO().addFollowCount(userFollowPO.getMeeting().getMeetingId());
        return id;
    }

    @Override
    public void updateUserFollow(UserFollowPO userFollowPO) throws Exception {
        getUserFollowDAO().updateUserFollow(userFollowPO);
    }

    @Override
    public void removeUserFollow(UserFollowPO userFollowPO) throws Exception {
        getUserFollowDAO().removeUserFollow(userFollowPO);
        getMeetingDAO().subFollowCount(userFollowPO.getMeeting().getMeetingId());
    }

    @Override
    public QueryResults<UserFollowPO> queryUserFollow(
            UserFollowQueryParas userFollowQueryParas) throws Exception {
        QueryStruct queryStruct = new QueryStruct();
        List<String> tableList = new ArrayList<String>();
        List<String> returnObjectList = new ArrayList<String>();
        
        tableList.add(UserFollowServiceParas.USER_FOLLOW);
        returnObjectList.add(UserFollowServiceParas.USER_FOLLOW);
        
        queryStruct.setTableList(tableList);
        queryStruct.setReturnObjectList(returnObjectList);
        
        queryStruct = UserFollowQueryParasBuilder.userFollowQueryBuilder(queryStruct, userFollowQueryParas);
        QueryResults<UserFollowPO> queryResults = getUserFollowDAO().queryUserFollow(queryStruct);
        return queryResults;
    }

}
